<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="layui-col-xs6 layui-col-md8">
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>封禁历史信息</legend>
  </fieldset>
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend></legend>
  </fieldset>
  <table class="layui-table" lay-even="" lay-skin="nob">
    <tr>
      <td>封禁处理编号</td>
      <td>被封禁账号编号</td>
      <td>被封禁账号名字</td>
      <td>开始时间</td>
      <td>结束时间</td>
      <td>封禁是否生效</td>
    </tr>
    <tr th:each="j:${credits}">
      <td th:text="${j.getId()}"></td>
      <td th:text="${j.getBorrowerId()}"></td>
      <td th:text="${j.getBorrowerName()}"></td>
      <td th:text="${j.getBreachStart()}"></td>
      <td th:text="${j.getBreachEnd()}"></td>
      <td th:text="${j.getIsBreach()}==true?'是':'否'"></td>
    </tr>
  </table>
</div>
<div class="layui-col-xs6 layui-col-md4">
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>操作</legend>
  </fieldset>
  <form class="layui-form" action="" >
    <div class="layui-form-item">
      <label class="layui-form-label">结束日期</label>
      <div class="layui-input-block">
        <input type="text" name="end" id="end" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="ban">封禁</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>
  <form class="layui-form" action="" >
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="relieve">解封</button>
      </div>
    </div>
  </form>
</div>
<input type="hidden" th:value="${borrowerId}" id="id">
<script>
  layui.use(['form','laydate', 'layer'], function (){
    var laydate = layui.laydate,
            form = layui.form,
            $ = layui.jquery;
    form.render();
    laydate.render({
      elem: '#end',
      min: 0,
    });
    form.on('submit(relieve)', function (data) {
      console.log(1)
      layer.confirm('<div class="layui-inline">\n' +
              '      <label class="layui-form-label">验证密码</label>\n' +
              '      <div class="layui-input-inline">\n' +
              '        <input type="password" name="pwd" id="pwd" lay-verify="required" autocomplete="off" class="layui-input">\n' +
              '      </div>\n' +
              '    </div>', function (index) {
        $.ajax({
          url:"/relieve",
          type:"POST",
          data:{
            id:document.getElementById('id').value,
            pwd:document.getElementById('pwd').value
          },
          success:function (result){
            if (result.code==200){
              layer.msg("解封成功",{
                icon:6,
                time:500
              });
            }else {
              layer.msg(result.msg);
            }
          }
        });
        return false;
      });
      return false;
    });
    form.on('submit(ban)', function (data) {
      console.log(2)
      console.log(data)
      layer.confirm('<div class="layui-inline">\n' +
              '      <label class="layui-form-label">验证密码</label>\n' +
              '      <div class="layui-input-inline">\n' +
              '        <input type="password" name="pwd" id="pwd" lay-verify="required" autocomplete="off" class="layui-input">\n' +
              '      </div>\n' +
              '    </div>', function (index) {
        data = data.field;
        data['pwd'] = document.getElementById('pwd').value;
        data['id'] = document.getElementById('id').value;
        $.ajax({
          url:"/ban",
          type:"POST",
          data:data,
          success:function (result){
            if (result.code==200){
              layer.msg("封禁成功",{
                icon:6,
                time:500
              });
            }else {
              layer.msg(result.msg);
            }
          }
        });
        return false;
      });
      return false;
    });
  })
</script>
</body>
</html>